import dayjs from 'dayjs'

/**
 *
 *
 * @export
 * @param {number} count
 * @param {string} imgPath
 * @description 生成组织marker值数量
 */
export function renderMakerItemDom(
  count: number,
  imgPath: string,
  width: number
): HTMLDivElement {
  let pTop = 0
  switch (width) {
    case 20:
      pTop = 10
      break
    case 28:
      pTop = 6
      break
    case 39:
      pTop = 3
      break
    default:
      pTop = 3
  }

  const markerItemDom = document.createElement('div')
  markerItemDom.style.cssText = `width:${width}px;height:37px;position:relative;`
  const itemImg = document.createElement('img')
  itemImg.style.cssText = `position: absolute;left:0px;top:0px;width:${width}px;height:37px;overflow:hidden;z-index:1`
  itemImg.setAttribute('src', imgPath)
  const itemP = document.createElement('p')
  itemP.style.cssText = `position: absolute;left:0px;top:${pTop}px;width:${width}px;height:16px;font-size: 12px;color: #FFFFFF;line-height: 18px;text-align: center;font-family: ZQKHY;z-index:2`
  itemP.innerText = count.toString()
  markerItemDom.appendChild(itemImg)
  markerItemDom.appendChild(itemP)
  return markerItemDom
}

/**
 *
 * @param alermDate
 * @returns
 * @description 计算时间差
 */
export function getDuration(alermDate: string) {
  let durationText
  const years = dayjs().diff(alermDate, 'years')
  const days = dayjs().diff(alermDate, 'days')
  const hours = dayjs().diff(alermDate, 'hour')
  const minutes = dayjs().diff(alermDate, 'minute')
  const seconds = dayjs().diff(alermDate, 'second')

  if (years) {
    durationText = years + '年前'
  } else if (days) {
    durationText = days + '天前'
  } else if (hours) {
    durationText = hours + '小时前'
  } else if (minutes) {
    durationText = minutes + '分钟前'
  } else if (seconds) {
    durationText = seconds + '秒前'
  }
  return durationText
}
